﻿using System;
using Prism.Commands;
using Prism.Events;
using Prism.Mvvm;
using Prism.Regions;
using YF_Music.Core;
using YF_Music.Core.Events;
using YF_Music.Core.Mvvm;
using YF_Music.Modules.APP_My;

namespace YF_Music.ViewModels
{
  public class MainWindowViewModel : RegionViewModelBase
  {
    private string _title = "YF-Music";
    public string Title
    {
      get { return _title; }
      set { SetProperty(ref _title, value); }
    }
    private bool onlyShowPlayControl;
    /// <summary>
    /// 只显示播放控件 并触发上升
    /// </summary>
    public bool OnlyShowPlayControl
    {
      get { return onlyShowPlayControl; }
      set { SetProperty(ref onlyShowPlayControl, value); }
    }
    private bool _IsFloatingVisible = true;
    private readonly IEventAggregator eventAggregator;
    private readonly PublishCoreEvent _publishEvent;

    public bool IsFloatingVisible
    {
      get { return _IsFloatingVisible; }
      set { SetProperty(ref _IsFloatingVisible, value); }
    }

    public DelegateCommand ShowPlayMusicCommand { get; private set; }

    private bool CanShowPlayMusicCommandExcute()
    {
      return IsFloatingVisible;
    }

    private void ShowPlayMusic()
    {
      RegionManager.RequestNavigate(RegionNames.ContentRegion, App_My_ViewNames.PlayMusicView);
    
    }

    public MainWindowViewModel(IEventAggregator eventAggregator, IRegionManager regionManager,PublishCoreEvent  publishCoreEvent) : base(regionManager)
    {
      this.eventAggregator = eventAggregator;
      this._publishEvent = publishCoreEvent;
      this.eventAggregator.GetEvent<OnlyPlayControlEvent>().Subscribe(OnOnlyPalyShow);
      this.eventAggregator.GetEvent<IsFloatingVisibleEvent>().Subscribe(ChangeFloatingVisible);

      ShowPlayMusicCommand = new DelegateCommand(ShowPlayMusic, CanShowPlayMusicCommandExcute);
    }

    private void ChangeFloatingVisible(bool visible)
    {
      IsFloatingVisible = visible;
    }

    private void OnOnlyPalyShow(bool only)
    {
      OnlyShowPlayControl = only;
    }
  
  }
}
